
cc.Class({
    extends: cc.Component,

    properties: {
        skillProgress: cc.Prefab,
    },

    onLoad () {
        this.skillProgressPool = new cc.NodePool();
        for (let i = 0; i < 10; ++i) {
            let progress = cc.instantiate(this.skillProgress); 
            this.skillProgressPool.put(progress); 
        }
    },

    
    //创建技能条
    createSkillProgress(flag){
        var isCreate = true
        var children = this.node.children
        for (let i = children.length - 1; i>=0; i--) {   
            if(children[i].getComponent('skillProgressInfo')){
                var js = children[i].getComponent('skillProgressInfo')
                if (js.flag.string == flag) {
                    js.cd.progress = 1
                    isCreate = false
                    break;
                }
            }
        }

        if(isCreate) {
            let newfab = null
            if (this.skillProgressPool.size() > 0) {
                newfab = this.skillProgressPool.get();
            } else { 
                newfab = cc.instantiate(this.skillProgress)
            }
            newfab.parent = this.node
            newfab.zIndex = 2

            var js = newfab.getComponent('skillProgressInfo');
            js.flag.string = flag;
            js.cd.progress = 1

            // var seq = cc.moveTo(0.3, cc.v2(285, 180 - posy))
            // newfab.runAction(seq);
          
        }
    },


    //回收技能条
    delProgress: function (progress) {
        this.skillProgressPool.put(progress); 
    },


    //清空所有技能条
    clearProgress(){
        var children = this.node.children
        for (let i = children.length - 1; i>=0; i--) {
            var jb = children[i].getComponent('skillProgressInfo');
            if(jb){
                this.delProgress(children[i])
            }
        }
    },



});
